﻿using System;
using System.Windows.Forms;

using DreamCube.Foundation.Basic.Utility;

namespace ShopHelper.BLL
{
    public static class ShopFacotry
    {
        /// <summary>
        /// 根据URL创建合适的html商品元素解析对象
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static ItemHtmlElement CreateItemHtmlElement(HtmlElement target)
        {
            if (target == null || target.Parent == null) return null;
            //获取父html元素，也就是包含其图片的<a>标签
            target = target.Parent;
            if (String.Compare(target.TagName, "a", true) == 0)
            {
                String[] href = MyString.SubStringBetweenStr(target.OuterHtml, "href=\"", "\"", false, true);
                if (href != null && href.Length > 0)
                    if (href[0].StartsWith(Properties.Resources.TB_GoodsUrlPrefix)) return new TB_ItemHtmlElement(target);
            }
            return null;
        }
    }
}
